package com.mybatistest.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "返回数据对象", description = "返回数据对象")
public class ResponseData<T> {

    @ApiModelProperty(value = "状态码", required = true, example = "200")
    Integer code;
    @ApiModelProperty(value = "提示信息", example = "success")
    String msg;
    @ApiModelProperty(value = "返回数据")
    T data;
    public static <T> ResponseData<T> success(T data)
    {
        return new ResponseData<>(200,"success",data);
    }
    public static <T> ResponseData<T> success(String msg, T data){
        return new ResponseData<>(200,msg,data);
    }
    public static <T> ResponseData<T> success(String msg){
        return new ResponseData<>(200,msg,null);
    }
    public static <T> ResponseData<T> fail()
    {
        return new ResponseData<>(400,"fail",null);
    }
    public static <T> ResponseData<T> fail(String msg)
    {
        return new ResponseData<>(400,msg,null);
    }
    public static <T> ResponseData<T> fail(String msg, T data)
    {
        return new ResponseData<>(400, msg, data);
    }
}
